//
//  CLCustomViewController.m
//  Charles
//
//  Created by Charles on 2019/7/6.
//  Copyright © 2019 charles. All rights reserved.
//

#import "CLCustomViewController.h"
#import "CLCustomButton.h"
#import "CLCustomContentView.h"
#import <objc/runtime.h>

@interface CLCustomViewController (){
    CLCustomContentView *_contentView;
}

@property (nonatomic, assign) NSInteger myNumber;
@property (nonatomic, strong) void(^MyBlock)(void);

@end

@implementation CLCustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"_contentView next is %@",NSStringFromClass(self.nextResponder.class));

    NSLog(@"_contentView next is %@",NSStringFromClass(self.view.nextResponder.class));
    
    // 点击范围是一个圆的按钮
//    CLCustomButton *customButton = [[CLCustomButton alloc] initWithFrame:CGRectMake(100, 100, 120, 120)];
//    customButton.backgroundColor = [UIColor blueColor];
//    [customButton addTarget:self action:@selector(cutomButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:customButton];
    
    // 视图响应测试容器view
    CLCustomContentView *contentView = [[CLCustomContentView alloc]initWithFrame:CGRectMake(20, 320, 350, 350)];
    contentView.backgroundColor = [UIColor lightGrayColor];
    contentView.userInteractionEnabled = YES;
    [self.view addSubview:contentView];
    NSLog(@"_contentView next is %@",NSStringFromClass(contentView.nextResponder.class));
    
    // 容器的第一层子视图
    CLRedView *redView = [[CLRedView alloc]initWithFrame:CGRectMake(50, 50, 230, 230)];
    redView.backgroundColor = [UIColor redColor];
    redView.userInteractionEnabled = YES;
    [contentView addSubview:redView];
    
    // 容器的第一层视图的子视图
    CLYellowView *yellowView = [[CLYellowView alloc]initWithFrame:CGRectMake(10,50, 150, 100)];
    yellowView.backgroundColor = [UIColor yellowColor];
    yellowView.userInteractionEnabled = YES;
    [redView addSubview:yellowView];

    CLBlueView *blueView = [[CLBlueView alloc]initWithFrame:CGRectMake(50,70, 50, 50)];
    blueView.backgroundColor = [UIColor blueColor];
    [redView addSubview:blueView];
    blueView.userInteractionEnabled = YES;
    
    NSLog(@"_contentView next is %@",NSStringFromClass(blueView.nextResponder.class));
    self.myNumber = 2;
    __block NSString *name = @"";
    self.MyBlock = ^{
        name = @"AAA";
        NSLog(@"%@",name);
    };
    self.MyBlock();
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"视图出现了!!");
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}

- (void)cutomButtonEvent:(UIButton *)sender {
    NSLog(@"可以点击！！");
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    UIResponder *next = self.nextResponder;
//    NSLog(@"self.view Touched!! next is %@",NSStringFromClass(next.class));
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
